//
//  TableTxtChoiceViewCell.m
//  FCTools
//
//  Created by WJC on 2018/10/25.
//  Copyright © 2018 wjc. All rights reserved.
//

#import "TableTxtChoiceViewCell.h"
#import "WJCDefine.h"
//#import "SVProgressHUD.h"
//#import "MJExtension.h"
//#import "Masonry.h"
@interface TableTxtChoiceViewCell()
@property (nonatomic,strong) UILongPressGestureRecognizer *longG;

@end
@implementation TableTxtChoiceViewCell

-(void)setMenuGesutre:(BOOL)menuGesutre{
    _menuGesutre = menuGesutre;
    if (!_longG) {
        self.longG = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(gestureClick:)];
        [self.detailLabel addGestureRecognizer:self.longG];
    }
    if(menuGesutre){
        self.detailLabel.userInteractionEnabled = YES;
        
    }else{
        self.detailLabel.userInteractionEnabled = NO;
    }
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(16, 12, 150, 20)];
        self.titleLabel.font=font15;
        self.titleLabel.textColor=HEXC(0x232323);
       
        self.detailLabel=[[UILabel alloc]initWithFrame:CGRectMake(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+16, 12, WJCScreenW-(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+32), 20)];

        self.detailLabel.font=font15;
        self.detailLabel.textColor=HEXC(0xCCCCCC);
         self.detailLabel.textAlignment=NSTextAlignmentRight;
        self.titleLabel.text=@"";
        self.detailLabel.text=@"";
        [self.contentView addSubview: self.titleLabel];
        [self.contentView addSubview: self.detailLabel];
        
        self.btn=[UIButton buttonWithType:UIButtonTypeCustom];
        self.btn.frame=CGRectMake(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+16, 7, 30, 30);
        self.btn.titleLabel.font=font15;
        [self.btn setTitleColor:HEXC(0x238EFA) forState:UIControlStateNormal];
//        self.btn=[WJCCreateUI createButtonWithFrame:CGRectMake(0, 0, 29, 29) andFont:[UIFont systemFontOfSize:15] andTxtColor:WJCNewBlueColor andBackColor:nil andImage:[UIImage imageNamed:@"ic_payway"]];
        [self.contentView addSubview:self.btn];
        [self.btn sizeToFit];
//        if (IphonePlus) {
//            self.titleLabel.y=15;
//            self.detailLabel.y=15;
//            self.titleLabel.font=font17;
//            self.detailLabel.font=font17;
//        }
        self.btn.hidden=YES;
        [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-16);
            make.centerY.mas_equalTo(0);
        }];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.titleLabel.centerY = self.contentView.centerY;
    self.detailLabel.centerY = self.contentView.centerY;
    self.btn.centerY = self.contentView.centerY;
}
-(instancetype)initGetImageWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.leftImage=[[UIImageView alloc] initWithFrame:CGRectMake(16, 12, 24, 24)];
        [self.contentView addSubview: self.leftImage];
        self.titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(42, 12, 150, 20)];
        self.titleLabel.font=font15;
        self.titleLabel.textColor=HEXC(0x232323);
        
        self.detailLabel=[[UILabel alloc]initWithFrame:CGRectMake(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+16, 12, WJCScreenW-(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+32), 20)];
        self.detailLabel.font=font15;
        self.detailLabel.textColor=HEXC(0x646262);
        self.detailLabel.textAlignment=NSTextAlignmentRight;
        self.titleLabel.text=@"标题";
        self.detailLabel.text=@"标题";
        [self.contentView addSubview: self.titleLabel];
        [self.contentView addSubview: self.detailLabel];
        self.btn=[UIButton buttonWithType:UIButtonTypeCustom];
        self.btn.frame=CGRectMake(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+16, 7, 30, 30);
        self.btn.titleLabel.font=font15;
        [self.btn setTitleColor:HEXC(0x238EFA) forState:UIControlStateNormal];
            //        self.btn=[WJCCreateUI createButtonWithFrame:CGRectMake(0, 0, 29, 29) andFont:[UIFont systemFontOfSize:15] andTxtColor:WJCNewBlueColor andBackColor:nil andImage:[UIImage imageNamed:@"ic_payway"]];
        [self.contentView addSubview:self.btn];
        [self.btn sizeToFit];
//        if (IphonePlus) {
//            self.titleLabel.y=15;
//            self.detailLabel.y=15;
//            self.btn.y=10;
//            self.titleLabel.font=font17;
//            self.detailLabel.font=font17;
//            self.btn.titleLabel.font=font17;
//        }
        self.btn.hidden=YES;
        
    }
    return self;
}
-(instancetype)initGetRightImageWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.leftImage=[[UIImageView alloc] initWithFrame:CGRectMake(16, 12, 24, 24)];
        [self.contentView addSubview: self.leftImage];
        [self.leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-16);
            make.height.and.width.mas_equalTo(24);
            make.centerY.mas_equalTo(0);
        }];
        WJCSETLRViewBorderRadius(self.leftImage, 4);
        self.titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(42, 12, 150, 20)];
        self.titleLabel.font=font15;
        self.titleLabel.textColor=HEXC(0x232323);
        [self.contentView addSubview: self.titleLabel];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(16);
            make.centerY.mas_equalTo(0);
        }];
        self.detailLabel=[[UILabel alloc]initWithFrame:CGRectMake(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+16, 12, WJCScreenW-(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+32), 20)];
        self.detailLabel.font=font15;
        self.detailLabel.textColor=HEXC(0x646262);
        self.detailLabel.textAlignment=NSTextAlignmentRight;
        [self.contentView addSubview: self.detailLabel];
        WJCWeakSelf
        [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.leftImage.mas_left).mas_offset(8);
            make.centerY.mas_equalTo(0);
        }];
        
        
    }
    return self;
}
-(void)setfit{
    [self.titleLabel sizeToFit];
    if(self.leftImage.image){
        self.titleLabel.x=self.leftImage.x+self.leftImage.width+8;
        self.leftImage.centerY=self.titleLabel.centerY;
    }
 self.detailLabel.frame=CGRectMake(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+16, 12, self.width-(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+(self.accessoryType==UITableViewCellAccessoryDisclosureIndicator?56:36)), self.detailLabel.height==0?20:self.detailLabel.height);
    if (!self.btn.hidden) {
      self.detailLabel.frame=CGRectMake(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+32+self.btn.frame.size.width, 12, self.width-(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+(self.accessoryType==UITableViewCellAccessoryDisclosureIndicator?56:36)), self.detailLabel.height);
    }

    [self layoutIfNeeded];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)gestureClick:(UILongPressGestureRecognizer *)gesture
{
    if (gesture.state == UIGestureRecognizerStateBegan) {

        [self becomeFirstResponder];
        UIMenuController *menuController = [UIMenuController sharedMenuController];
        UIMenuItem *copyItem = [[UIMenuItem alloc] initWithTitle:@"复制" action:@selector(handleMenuCopyItemAction:)];
        menuController.menuItems = @[copyItem];
        [menuController setTargetRect:gesture.view.frame inView:gesture.view.superview];
        [menuController setMenuVisible:YES animated:YES];
        [UIMenuController sharedMenuController].menuItems=nil;
    }

}

- (void)handleMenuCopyItemAction:(UIMenuItem *)menuItem
{
    [[UIPasteboard generalPasteboard] setString:self.detailLabel.text];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
